<?php

declare(strict_types=1);

namespace App\Controller\Admin\V1\Shop;

use App\Controller\Admin\V1\Controllers;
use App\Services\Shop\Shop as ShopServices;

/**
 * Class Shop
 * @author zx
 * @package App\Controller\Admin\V1\Shop
 */
class Shop extends Controllers
{
    public function __construct(
        ShopServices $shopServices
    )
    {
        parent::__construct();
        $this->services = $shopServices;
    }

    /**
     * 分页
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Throwable
     */
    public function page()
    {
        $query = $this->query();

        [$field, $order] = $this->orderMap();
        $page = $this->services
            ->search($query)
            ->orderBy($field, $order)
            ->paginate($this->getLimit());

        return success(compact('page'));
    }
}
